import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/component/circle_progress.dart';
import 'package:whale/helper/component/progress/line_progress.dart';
import 'package:whale/helper/utils/util.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class ProgressDemoDartPage extends GetView<ProgressDemoDartController> {
  const ProgressDemoDartPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    final state = controller.state;
    return ListView(
      padding: EdgeInsets.symmetric(vertical: 30.r, horizontal: 20.r),
      children: [
        Container(
          height: 30,
          child: Text('拖动改变进度'),
        ),
        LineProgress(
          onChanged: (value) {
            controller.state.progress = value;
            controller.update();
          },
        ),
        SizedBox(height: 20.r),
        Container(
          width: 100.r,
          height: 100.r,
          child: CustomPaint(
            painter: CircleOpenProgress(
              state.progress,
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [Text(state.progress.progress)],
            ),
          ),
        ),
        TextFormField(
          textInputAction: TextInputAction.send,
          keyboardType: TextInputType.text,
          onSaved: (value) {
            Get.log(value ?? '--');
          },
          scrollPadding: EdgeInsets.zero,
          minLines: 1,
          maxLines: 3,
          decoration: InputDecoration(
              contentPadding:
                  EdgeInsets.symmetric(horizontal: 12.r, vertical: 5.r),
              fillColor: Colors.brown,
              filled: true,
              hintText: '说点什么',
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(20.r),
                borderSide: BorderSide.none,
              ),
              disabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(20.r),
                borderSide: BorderSide.none,
              ),
              focusedBorder: InputBorder.none),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProgressDemoDartController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("进度")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
